{% extends "stream/base.html" %}

{% block title %}
Subscription details
{% endblock %}

{% block scripts %}
    <script type="text/javascript" src="/js/common.js"></script>
    <script>
        function SubmitForm(e) {
            $.post(e.target.form.action, $(e.target.form).serialize());
        }

        function ResetForm(e) {
            e.target.form.reset();
        }

        function DeleteForm(e) {
            $(e.target.form).empty();
        }

        function Init() {
            $('#submit-subscription').bind('click', function() { $('#data').submit(); return false; });
            $('#new-filter').bind('click', function() {
                {% autoescape off %}
                    new_form = $('<form id="new-form" class="FilterEdit" method="POST" action="{% url stream.views.filterEdit %}">{{ new_filter_form_text }}<br/>Apply the filter to existing messages: <input name="update" type="checkbox" /></form>');
                {% endautoescape %}
                new_form.append(
                    $('<div/>').append(
                        $('<input type="reset"/>')
                    ).append(
                        $('<input type="button" value="Save" />').bind('click', SubmitForm)
                    ).append(
                        $('<input type="button" value="Delete" />').bind('click', DeleteForm)
                    )
                )
                new_form[0].subscription.value = {{ subscription_form.instance.id }};
                $('#filters').append(new_form)
            });
            $("input[name='update-filter']").bind('click', SubmitForm);
            $("input[name='delete-filter']").bind('click', function(e) {
                $.post('/filterDelete/' + e.target.form.id.value);
            })
        }

        $(document).ready(Init);
    </script>
{% endblock %}

{% block content %}
Edit subscription details:
<form id="data" class="SubscriptionEdit" method="POST" action="{% url stream.views.subscriptionEdit %}">
    {% with subscription_form as form %}
        {% include "stream/form_snippet.html" %}
    {% endwith %}
    <div>
        <a id="submit-subscription" href="/{{ viewer.id }}">Save</a>
        <a id="cancel-subscription" href="/{{ viewer.id }}">Cancel</a>
    </div>
</form>
Edit subscription filters:
<div id="filters">
    {% for form in filter_forms %}
        <form onsubmit="javascript:alert('I hate this fucking world')" id="filter-{{ form.instance.id }}" class="FilterEdit" method="POST" action="/filterEdit/{{ form.instance.id }}">
            {% include "stream/form_snippet.html" %}
            <div>
                <input type="reset"/>
                <input type="button" name="update-filter" value="Update" />
                <input type="button" name="delete-filter" value="Delete" />
            </div>
        </form>
    {% endfor %}
</div>
<button id="new-filter">Create new filter</a>
{% endblock%}

